package com.example.webfluxdemo;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.Map;

/**
 * Created by victor on 2021/10/20 10:18.
 */
@Component
public class ELKLog {
    private final Cache<String, Map<String, String>> cache;

    public ELKLog() {
        cache = Caffeine.newBuilder()
                .expireAfterWrite(Duration.ofSeconds(5))
                .maximumSize(50000)
                .build();
    }

    public void add(String requestId, String key, String value) {
        Map<String, String> map = cache.getIfPresent(requestId);
        if (map != null) {
            map.put(key, value);
        }
    }

    public void write(String requestId) {

    }
}
